﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.model;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.门店下单
{
    /// <summary>
    /// 门店下单充血模型
    /// </summary>
    class OrderModel
    {
        private List<OrderDto> orderDtos = new List<OrderDto>();

        #region 属性
        public List<OrderDto> OrderDtos { get => orderDtos; set => orderDtos = value; }
        #endregion

        public OrderModel buildAddOrderDtos(Dto定制下单 dto定制下单) {
            this.orderDtos.Add(new OrderDto(dto定制下单));
            return this;
        }
        /// <summary>
        /// 增加辅料信息注入
        /// </summary>
        /// <param name="dto定制下单"></param>
        /// <param name="dto辅料"></param>
        /// <returns></returns>
        public OrderModel buildAddOrderDtos(Dto定制下单 dto定制下单, StyleAccessoryItemsDTO dto辅料)
        {
            this.orderDtos.Add(new OrderDto(dto定制下单).build辅料信息(dto辅料));
            return this;
        }

        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public OrderModel buildDeletaOrderDtos(String id) {
            foreach (OrderDto orderDto in this.OrderDtos) {
                if (id.Equals(orderDto.ID)) {
                    this.OrderDtos.Remove(orderDto);
                    return this;
                }
            }
            return this;
        }

        public OrderModel buildCustomer()
        {
            foreach(OrderDto orderDto in this.OrderDtos)
            {
                orderDto.CUSTOMER_ID = Frm客户.cUSTOMER_ID.ToString();
                orderDto.CUSTOMER_COUNT_ID = Frm客户.customer_countid.ToString();
                orderDto.CUSTOMER_NAME = Frm客户.customer_name;
                orderDto.ADDRESS_ID = Frm客户.aDDRESS_ID.ToString();
            }
            return this;
        }
        /// <summary>
        /// 订单存入数据库
        /// </summary>
        public void SaveOrderInDatabase(Enum订单类型 @enum)
        {
            this.buildCustomer();
            String str = FunctionHelper.JsonSerialization(this.OrderDtos);
            foreach (OrderDto orderDto in OrderDtos)
            {
                OrderService.DynamicSaveOrder(orderDto,@enum);
            }
        }
        /// <summary>
        /// 坚山下单用
        /// </summary>
        /// <param name="i"></param>
        public void SaveOrderInDatabase(int i)
        {
            this.buildCustomer();
            foreach (OrderDto orderDto in OrderDtos)
            {
                OrderService.DynamicSaveOrder(orderDto, Enum订单类型.坚山订单);
            }
        }
        public void CreateExcel并回执邮件()
        {

        }
    }
}
